package com.dq.domain.record.stockcheck;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;

import com.dq.domain.goods.Goods;
import com.dq.domain.goods.Product;
import com.dq.domain.sys.section.SysSection;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @Author luchangtong
 * @Date 2019/11/20 16:23
 */
@Data
@Entity
@ApiModel("库存盘点详情记录")
public class StockCheckRecord extends BaseEntity implements VO.ToVO {
    @ApiModelProperty("关联main")
    @ManyToOne
    protected StockCheckMain stockCheckMain;

    @ApiModelProperty("关联商品")
    @ManyToOne
    protected Goods goods;
    @ApiModelProperty("关联product")
    @ManyToOne
    protected Product product;

    @ApiModelProperty("门店")
    @ManyToOne
    protected SysSection org;

    @ApiModelProperty("进货数量")
    protected Long addall;
    @ApiModelProperty("出货数量-消耗")
    protected Long reduceloss;
    @ApiModelProperty("出货数量-售出")
    protected Long reducesell;
    @ApiModelProperty("库存结余")
    protected Long residuestock;


    @Data
    @ApiModel(value = "视图")
    public static class Vo implements VO {
        protected Long id;
        @ApiModelProperty("商品")
        protected Long goodsId;
        protected String goodsSmallImgUrl;
        protected String goodsNo;
        protected String goodsName;

        @ApiModelProperty("门店")
        protected Long orgId;
        protected String orgName;

        @ApiModelProperty("进货数量")
        protected Long addall;
        @ApiModelProperty("出货数量-消耗")
        protected Long reduceloss;
        @ApiModelProperty("出货数量-售出")
        protected Long reducesell;
        @ApiModelProperty("库存结余")
        protected Long residuestock;
        /** set 赋值 */
        @ApiModelProperty("实时库存")
        protected Long realstock;

        @ApiModelProperty("盘点时间, 点击盘点的时间")
        protected String createTimeMain;
        @ApiModelProperty("记录生成时间")
        protected String createTime;
        @ApiModelProperty("操作人")
        protected Long createUserId;
        protected String createUserName;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.getId();
        vo.goodsId = this.getGoods() == null ? null : this.getGoods().getId();
        vo.goodsSmallImgUrl = this.getGoods() == null ? "" : this.getGoods().getSmallImgUrl();
        vo.goodsNo = this.getGoods() == null ? "" : this.getGoods().getGoodsNo();
        vo.goodsName = this.getGoods() == null ? "" : this.getGoods().getGoodsName();
        vo.orgId = this.getOrg() == null ? null : this.getOrg().getId();
        vo.orgName = this.getOrg() == null ? "" : this.getOrg().getSimpleName();

        vo.addall = fmt(this.getAddall());
        vo.reduceloss = fmt(this.getReduceloss());
        vo.reducesell = fmt(this.getReducesell());
        vo.residuestock = fmt(this.getResiduestock());

        vo.createTimeMain = fmt(this.getStockCheckMain().getCreateTimeMain(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.createTime = fmt(this.getCreateTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.createUserId = this.createUser == null ? null : this.createUser.getId();
        vo.createUserName = this.createUser == null ? null : this.createUser.getUsername();

        return vo;
    }
}
